# Q-Project
# Models Module
# Copyright (C) 2010 by Andres Rocha, Miguel Ordo/ez, Edgar Sotelo
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from django.db import models
from Q.QApp.choices import SUBJECT_CHOICES

class User(models.Model):
    name            = models.CharField(max_length=30)
    last_name       = models.CharField(max_length=30)
    mail            = models.EmailField(primary_key=True)
    password        = models.CharField(max_length=10)
    
    def __unicode__(self):
        return '%s %s ' % (self.name, self.last_name)

class Question(models.Model):
    user            = models.ForeignKey(User, related_name='user_question')
    date_time       = models.DateTimeField(auto_now_add=True)
    question        = models.TextField()
    subject         = models.CharField(max_length=3, choices = SUBJECT_CHOICES)
    
    def __unicode__ (self):
        return '%s [%s](%s) pregunto: \n %s' % (self.user, self.get_subject_display(), self.date_time, self.question)

class Category_User(models.Model):
    user            = models.ManyToManyField(User, related_name='user_category')
    subject         = models.CharField(max_length=3, choices = SUBJECT_CHOICES, unique=True)

    def __unicode__(self):
        return self.subject

class Reply(models.Model):
    user            = models.ForeignKey(User, related_name='user_reply')
    question        = models.ForeignKey(Question, related_name='question_reply')
    date_time       = models.DateTimeField(auto_now_add=True)
    reply           = models.TextField()
    file            = models.FileField(upload_to='-%y-%m-%d')
    
    def __unicode__ (self):
        return '%s, %s' % (self.user, self.reply)